package fr.mywiki.view.array;

import java.util.List;

/** Represents one page of the array. */
public class ArrayPage {
	/** Titles of the columns */
	private String[] titles;

	/** The cells of the array */
	private String[][] cells;
	
	/** Current page */
	private int page;
	
	/** Number of filled lines */
	private int lines;
	
	/** What do we display if there is no element to display ? */
	private String noElementMessage;
	
	private ArrayPage()  {}
	
	/**
	 * Constructor, inits a array with specified numbers of lines and columns.
	 * 
	 * @param lines number of lines
	 * @param cols number of columns
	 */
	public ArrayPage(int lines, int cols, String msg) {
		titles = new String[cols];
		cells = new String[lines][cols];
		this.lines = lines;
		noElementMessage = msg;
	}

	public String[][] getCells() {
		return cells;
	}
	
	/**
	 * Returns the number of columns of the array.
	 * 
	 * @return the array's width.
	 */
	public int countCols() {
		return titles.length;
	}
	
	/**
	 * Returns the value of a cell.
	 * 
	 * @param line line number
	 * @param column column number
	 * @return a String object
	 */
	public String getCell(int line, int column) {
		return cells[line][column];
	}
	
	/**
	 * Sets the value of a specified element of the array.
	 * 
	 * @param line
	 *          line number
	 * @param col
	 *          column number
	 * @param value
	 *          value to put
	 */
	public void setCell(int line, int col, String value) {
		cells[line][col] = value;
	}
	
	/**
	 * Sets the value of a specified title of the array.
	 * 
	 * @param col
	 *          column number
	 * @param value
	 *          value to put
	 */
	public void setTitle(int col, String value) {
		titles[col] = value;
	}
	
	/**
	 * Returns the title of the specified column.
	 * 
	 * @param column the column number
	 * @return a String object
	 */
	public String getTitle(int column) {
		return titles[column];
	}

	public void setCells(String[][] cells) {
		this.cells = cells;
	}

	public String[] getTitles() {
		return titles;
	}

	public void setTitles(String[] titles) {
		this.titles = titles;
	}
	
	public void setTitles(List titles) {
		this.titles = new String[titles.size()];
		for(int i=0;i<titles.size();i++)
			this.titles[i] = (String)titles.get(i);
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getLines() {
		return lines;
	}

	public void setLines(int lines) {
		this.lines = lines;
	}
	
	/**
	 * Returns true if the current page contains no element.
	 * 
	 * @return true if lines=0, false otherwise.
	 */
	public boolean isEmpty() {
		return lines==0;
	}

	public String getNoElementMessage() {
		return noElementMessage;
	}
}
